package com.toe.recommend.webapi.controller;


import com.toe.common.restful.JsonPage;
import com.toe.common.restful.JsonResult;
import com.toe.pojo.vo.recommend.RecommendClassesVO;
import com.toe.pojo.vo.recommend.RecommendClassesVideoVO;
import com.toe.recommend.service.RecommendClassesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 陶涛
 * @since 2022-07-19
 */
@RestController
@RequestMapping("/recommend-classes")
@Api(tags = "推荐免费课模块")
public class RecommendClassesController {

    @Autowired
    RecommendClassesService recommendClassesService;

//    // http://ironknight2.gnway.cc/recommend-classes/insert2
//    @PostMapping("/insert2")
//    public JsonResult<Void> insert(AddClassDTO classDTO, MultipartFile file) {
//        recommendClassesService.insert(classDTO, file);
//        return JsonResult.ok();
//    }
//
//    @PostMapping("/insert")
//    public JsonResult<Void> insert(RecommendAddClassDTO classDTO, MultipartFile file) {
//        recommendClassesService.insert(classDTO, FileUtils.multipartFileToFile(file));
//        return JsonResult.ok();
//    }
//
//    @GetMapping("/delete/{id}")
//    @ApiOperation("删除免费课")
//    @ApiImplicitParam(value = "课程id", name = "id",
//            required = true, dataType = "long", example = "1")
//    public JsonResult<Void> delete(
//            @PathVariable Long id) {
//        recommendClassesService.deleteById(id);
//        return JsonResult.ok();
//    }

    @GetMapping("/{id}")
    @ApiOperation("观看免费课")
    @ApiImplicitParam(value = "课程id", name = "id",
            required = true, dataType = "long", example = "1")
    public JsonResult<RecommendClassesVideoVO> getClassVideoById(
            @PathVariable Long id) {
        return JsonResult.ok(
                recommendClassesService.getClassVideoById(id));
    }

    @GetMapping("/classes")
    @ApiOperation("推荐免费课")
    public JsonResult<List<RecommendClassesVO>> recommendClasses() {
        return JsonResult.ok(recommendClassesService.recommendClasses());
    }

    @GetMapping("/page-classes")
    @ApiOperation("分页查询免费课")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码", name = "pageNum",
                    required = true, dataType = "int", example = "1"),
            @ApiImplicitParam(value = "每页大小", name = "pageSize",
                    required = true, dataType = "int", example = "10")
    })
    public JsonResult<JsonPage<RecommendClassesVO>> getClasses(int pageNum, int pageSize) {
        return JsonResult.ok(recommendClassesService.getClasses(pageNum, pageSize));
    }

    // http://ironknight.gnway.cc/recommend-classes/download/52
    // http://localhost:10006/recommend-classes/download/1
    @GetMapping("/download/{id}")
    @ApiOperation("下载免费课")
    public void download(
            @PathVariable Long id, HttpServletResponse response) {
        recommendClassesService.download(id, response);
    }

}

